package com.zhang.common.core.exception.file;

import org.apache.commons.fileupload.FileUploadException;

import java.util.Arrays;

/**
 * @Class com.zhang.common.core.exception.file
 * @Author zhang
 * @Date 2025/9/11 17:54
 * @Description
 **/
public class FileInvalidExtensionException extends FileUploadException {

    /**
     * 序列化序号
     */
    private static final long serialVersionUID = 3986928472135635611L;

    /**
     * 允许的后缀数组
     */
    private String[] allowedExtension;

    /**
     * 后缀
     */
    private String extension;

    /**
     * 文件名称
     */
    private String filename;

    /**
     * 构造函数初始化
     *
     * @param allowedExtension 允许的后缀数组
     * @param extension 后缀
     * @param filename 文件名称
     */
    public FileInvalidExtensionException(String[] allowedExtension, String extension, String filename) {
        super("filename : [" + filename + "], extension : [" + extension + "], allowed extension : [" + Arrays.toString(allowedExtension) + "]");
        this.allowedExtension = allowedExtension;
        this.extension = extension;
        this.filename = filename;
    }

    /**
     * 获取允许的后缀数组
     *
     * @return 返回允许的后缀数组
     */
    public String[] getAllowedExtension() {
        return allowedExtension;
    }

    /**
     * 获取后缀
     *
     * @return 返回后缀
     */
    public String getExtension() {
        return extension;
    }

    /**
     * 获取文件名称
     *
     * @return 返回文件名称
     */
    public String getFilename() {
        return filename;
    }

    /**
     * 图片文件后缀异常
     *
     */
    public static class InvalidImageExtensionException extends FileInvalidExtensionException {

        /**
         * 序列化序号
         */
        private static final long serialVersionUID = 8911423843405259104L;

        /**
         * 构造函数初始化
         *
         * @param allowedExtension 允许的后缀数组
         * @param extension 后缀
         * @param filename 文件名称
         */
        public InvalidImageExtensionException(String[] allowedExtension, String extension, String filename) {
            super(allowedExtension, extension, filename);
        }
    }

    /**
     * Flash 文件后缀异常
     *
     */
    public static class InvalidFlashExtensionException extends FileInvalidExtensionException {

        /**
         * 序列化序号
         */
        private static final long serialVersionUID = 961497734117212972L;

        /**
         * 构造函数初始化
         *
         * @param allowedExtension 允许的后缀数组
         * @param extension 后缀
         * @param filename 文件名称
         */
        public InvalidFlashExtensionException(String[] allowedExtension, String extension, String filename) {
            super(allowedExtension, extension, filename);
        }
    }

    /**
     * 媒体文件后缀异常
     */
    public static class InvalidMediaExtensionException extends FileInvalidExtensionException {

        /**
         * 序列化序号
         */
        private static final long serialVersionUID = 3416233236322601740L;

        /**
         * 构造函数初始化
         *
         * @param allowedExtension 允许的后缀数组
         * @param extension 后缀
         * @param filename 文件名称
         */
        public InvalidMediaExtensionException(String[] allowedExtension, String extension, String filename) {
            super(allowedExtension, extension, filename);
        }
    }

    /**
     * 视频文件后缀异常
     */
    public static class InvalidVideoExtensionException extends FileInvalidExtensionException {

        /**
         * 序列化序号
         */
        private static final long serialVersionUID = 6125351059514012367L;

        /**
         * 构造函数初始化
         *
         * @param allowedExtension 允许的后缀数组
         * @param extension 后缀
         * @param filename 文件名称
         */
        public InvalidVideoExtensionException(String[] allowedExtension, String extension, String filename) {
            super(allowedExtension, extension, filename);
        }
    }
    
}
